package com.java.connection;

import java.sql.Connection;
import java.sql.DriverManager;

public class DatabaseConnection {

	public Connection getConnection() {
		Connection conn = null;
		try {
			String userName = "root";
			String password = "nvish";
			String url = "jdbc:mysql://localhost:3306/lenaBank";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(url, userName, password);
			System.out.println("Database connection established");
		} catch (Exception e) {
			System.err.println("Cannot connect to database server: " +e.getMessage());
		} 
		return conn;

	}
	
	protected void closeConnection(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (Exception e) {
				System.out.println("Exception in getCustomer in closing connection: "+e);
			}
		}
	}
}
